import requests

def getHTMLText(url):
    try:
        r=requests.get(url)
        r.raise_for_status()
        print(r.status_code)
        r.encoding=r.apparent_encoding
        return r.text
    except:
        print("抓取失败")
def output(data=''):
    file = open("ip138.html","w",encoding="utf-8")
    file.write(data)
    file.close()
    
def main():
    url = "http://m.ip138.com/ip.asp?ip="
    ipurl = input("请输入一个网站：")
    urls =url+ipurl
    print(urls)
    dome = getHTMLText(urls)
    output(dome)
    print("抓取成功")
    


main()
